package homework.day04; 
 /*
 @Time: 2022/7/15 18:16
 @Author:GShuai
 @File:Test01.class
 @Software:IntelliJ IDEA
*/

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/**
 * 改正下面程序的错误
 * 向文件testpw.txt中以UTF-8编码写入一行字符串：
 * 你好!我喜欢java!
 * 单词记一记:
 * print 打印

 */
public class Test01 {
    //缺少main方法
    public static void main(String[] args) {
        try (
                FileOutputStream fos = new FileOutputStream("testpw.txt");
             //   OutputStreamWriter osw = new OutputStreamWriter(fos,"UFT-8");
                OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-8");  ////StandardCharsets.UTF_8 或者"UTF-8"
                BufferedWriter bw = new BufferedWriter(osw);
                PrintWriter pw = new PrintWriter(bw);
        ) {
            pw.println("你好!我喜欢java!");
           //  system.out.println("写出完毕!");
            System.out.println("写出完毕!");

              /*
                 java.io.Unsupported Encoding Exception: UFT-8
                         不支持      字符集    异常
             */
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("出错了!");
        }
    }

}
